// $ANTLR 3.4 src/vb/week3/calc/Calc.g 2012-05-25 16:21:46

package vb.week3.calc;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.runtime.tree.*;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class CalcParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "BECOMES", "COLON", "COMMENT", "DIGIT", "DIVIDEBY", "DO", "ELSE", "EQUAL", "GREATEREQUAL", "GREATERTHAN", "IDENTIFIER", "IF", "INTEGER", "KOMMA", "LESSEQUAL", "LESSTHAN", "LETTER", "LOWER", "LPAREN", "MINUS", "NOTEQUAL", "NUMBER", "PLUS", "PRINT", "PROGRAM", "RPAREN", "SEMICOLON", "SWAP", "THEN", "TIMES", "UPPER", "VAR", "WHILE", "WS"
    };

    public static final int EOF=-1;
    public static final int BECOMES=4;
    public static final int COLON=5;
    public static final int COMMENT=6;
    public static final int DIGIT=7;
    public static final int DIVIDEBY=8;
    public static final int DO=9;
    public static final int ELSE=10;
    public static final int EQUAL=11;
    public static final int GREATEREQUAL=12;
    public static final int GREATERTHAN=13;
    public static final int IDENTIFIER=14;
    public static final int IF=15;
    public static final int INTEGER=16;
    public static final int KOMMA=17;
    public static final int LESSEQUAL=18;
    public static final int LESSTHAN=19;
    public static final int LETTER=20;
    public static final int LOWER=21;
    public static final int LPAREN=22;
    public static final int MINUS=23;
    public static final int NOTEQUAL=24;
    public static final int NUMBER=25;
    public static final int PLUS=26;
    public static final int PRINT=27;
    public static final int PROGRAM=28;
    public static final int RPAREN=29;
    public static final int SEMICOLON=30;
    public static final int SWAP=31;
    public static final int THEN=32;
    public static final int TIMES=33;
    public static final int UPPER=34;
    public static final int VAR=35;
    public static final int WHILE=36;
    public static final int WS=37;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public CalcParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public CalcParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected TreeAdaptor adaptor = new CommonTreeAdaptor();

public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
    public String[] getTokenNames() { return CalcParser.tokenNames; }
    public String getGrammarFileName() { return "src/vb/week3/calc/Calc.g"; }


    public static class program_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "program"
    // src/vb/week3/calc/Calc.g:55:1: program : statementsanddeclarations EOF -> ^( PROGRAM statementsanddeclarations ) ;
    public final CalcParser.program_return program() throws RecognitionException {
        CalcParser.program_return retval = new CalcParser.program_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token EOF2=null;
        CalcParser.statementsanddeclarations_return statementsanddeclarations1 =null;


        Object EOF2_tree=null;
        RewriteRuleTokenStream stream_EOF=new RewriteRuleTokenStream(adaptor,"token EOF");
        RewriteRuleSubtreeStream stream_statementsanddeclarations=new RewriteRuleSubtreeStream(adaptor,"rule statementsanddeclarations");
        try {
            // src/vb/week3/calc/Calc.g:56:5: ( statementsanddeclarations EOF -> ^( PROGRAM statementsanddeclarations ) )
            // src/vb/week3/calc/Calc.g:56:9: statementsanddeclarations EOF
            {
            pushFollow(FOLLOW_statementsanddeclarations_in_program776);
            statementsanddeclarations1=statementsanddeclarations();

            state._fsp--;

            stream_statementsanddeclarations.add(statementsanddeclarations1.getTree());

            EOF2=(Token)match(input,EOF,FOLLOW_EOF_in_program778);  
            stream_EOF.add(EOF2);


            // AST REWRITE
            // elements: statementsanddeclarations
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 57:13: -> ^( PROGRAM statementsanddeclarations )
            {
                // src/vb/week3/calc/Calc.g:57:17: ^( PROGRAM statementsanddeclarations )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(
                (Object)adaptor.create(PROGRAM, "PROGRAM")
                , root_1);

                adaptor.addChild(root_1, stream_statementsanddeclarations.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }


            retval.tree = root_0;

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "program"


    public static class statementsanddeclarations_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "statementsanddeclarations"
    // src/vb/week3/calc/Calc.g:60:1: statementsanddeclarations : ( ( declaration SEMICOLON !)* ( statement SEMICOLON !) )* ;
    public final CalcParser.statementsanddeclarations_return statementsanddeclarations() throws RecognitionException {
        CalcParser.statementsanddeclarations_return retval = new CalcParser.statementsanddeclarations_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token SEMICOLON4=null;
        Token SEMICOLON6=null;
        CalcParser.declaration_return declaration3 =null;

        CalcParser.statement_return statement5 =null;


        Object SEMICOLON4_tree=null;
        Object SEMICOLON6_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:61:5: ( ( ( declaration SEMICOLON !)* ( statement SEMICOLON !) )* )
            // src/vb/week3/calc/Calc.g:61:9: ( ( declaration SEMICOLON !)* ( statement SEMICOLON !) )*
            {
            root_0 = (Object)adaptor.nil();


            // src/vb/week3/calc/Calc.g:61:9: ( ( declaration SEMICOLON !)* ( statement SEMICOLON !) )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==DO||(LA2_0 >= IDENTIFIER && LA2_0 <= IF)||LA2_0==LPAREN||LA2_0==NUMBER||LA2_0==PRINT||LA2_0==SWAP||LA2_0==VAR) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // src/vb/week3/calc/Calc.g:61:10: ( declaration SEMICOLON !)* ( statement SEMICOLON !)
            	    {
            	    // src/vb/week3/calc/Calc.g:61:10: ( declaration SEMICOLON !)*
            	    loop1:
            	    do {
            	        int alt1=2;
            	        int LA1_0 = input.LA(1);

            	        if ( (LA1_0==VAR) ) {
            	            alt1=1;
            	        }


            	        switch (alt1) {
            	    	case 1 :
            	    	    // src/vb/week3/calc/Calc.g:61:11: declaration SEMICOLON !
            	    	    {
            	    	    pushFollow(FOLLOW_declaration_in_statementsanddeclarations824);
            	    	    declaration3=declaration();

            	    	    state._fsp--;

            	    	    adaptor.addChild(root_0, declaration3.getTree());

            	    	    SEMICOLON4=(Token)match(input,SEMICOLON,FOLLOW_SEMICOLON_in_statementsanddeclarations826); 

            	    	    }
            	    	    break;

            	    	default :
            	    	    break loop1;
            	        }
            	    } while (true);


            	    // src/vb/week3/calc/Calc.g:61:36: ( statement SEMICOLON !)
            	    // src/vb/week3/calc/Calc.g:61:37: statement SEMICOLON !
            	    {
            	    pushFollow(FOLLOW_statement_in_statementsanddeclarations832);
            	    statement5=statement();

            	    state._fsp--;

            	    adaptor.addChild(root_0, statement5.getTree());

            	    SEMICOLON6=(Token)match(input,SEMICOLON,FOLLOW_SEMICOLON_in_statementsanddeclarations834); 

            	    }


            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "statementsanddeclarations"


    public static class declarations_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "declarations"
    // src/vb/week3/calc/Calc.g:64:1: declarations : ( declaration SEMICOLON !)* ;
    public final CalcParser.declarations_return declarations() throws RecognitionException {
        CalcParser.declarations_return retval = new CalcParser.declarations_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token SEMICOLON8=null;
        CalcParser.declaration_return declaration7 =null;


        Object SEMICOLON8_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:65:5: ( ( declaration SEMICOLON !)* )
            // src/vb/week3/calc/Calc.g:65:9: ( declaration SEMICOLON !)*
            {
            root_0 = (Object)adaptor.nil();


            // src/vb/week3/calc/Calc.g:65:9: ( declaration SEMICOLON !)*
            loop3:
            do {
                int alt3=2;
                int LA3_0 = input.LA(1);

                if ( (LA3_0==VAR) ) {
                    alt3=1;
                }


                switch (alt3) {
            	case 1 :
            	    // src/vb/week3/calc/Calc.g:65:10: declaration SEMICOLON !
            	    {
            	    pushFollow(FOLLOW_declaration_in_declarations862);
            	    declaration7=declaration();

            	    state._fsp--;

            	    adaptor.addChild(root_0, declaration7.getTree());

            	    SEMICOLON8=(Token)match(input,SEMICOLON,FOLLOW_SEMICOLON_in_declarations864); 

            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "declarations"


    public static class statements_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "statements"
    // src/vb/week3/calc/Calc.g:68:1: statements : ( statement SEMICOLON !)+ ;
    public final CalcParser.statements_return statements() throws RecognitionException {
        CalcParser.statements_return retval = new CalcParser.statements_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token SEMICOLON10=null;
        CalcParser.statement_return statement9 =null;


        Object SEMICOLON10_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:69:5: ( ( statement SEMICOLON !)+ )
            // src/vb/week3/calc/Calc.g:69:9: ( statement SEMICOLON !)+
            {
            root_0 = (Object)adaptor.nil();


            // src/vb/week3/calc/Calc.g:69:9: ( statement SEMICOLON !)+
            int cnt4=0;
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( (LA4_0==DO||(LA4_0 >= IDENTIFIER && LA4_0 <= IF)||LA4_0==LPAREN||LA4_0==NUMBER||LA4_0==PRINT||LA4_0==SWAP) ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // src/vb/week3/calc/Calc.g:69:10: statement SEMICOLON !
            	    {
            	    pushFollow(FOLLOW_statement_in_statements891);
            	    statement9=statement();

            	    state._fsp--;

            	    adaptor.addChild(root_0, statement9.getTree());

            	    SEMICOLON10=(Token)match(input,SEMICOLON,FOLLOW_SEMICOLON_in_statements893); 

            	    }
            	    break;

            	default :
            	    if ( cnt4 >= 1 ) break loop4;
                        EarlyExitException eee =
                            new EarlyExitException(4, input);
                        throw eee;
                }
                cnt4++;
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "statements"


    public static class declaration_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "declaration"
    // src/vb/week3/calc/Calc.g:72:1: declaration : VAR ^ IDENTIFIER COLON ! type ;
    public final CalcParser.declaration_return declaration() throws RecognitionException {
        CalcParser.declaration_return retval = new CalcParser.declaration_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token VAR11=null;
        Token IDENTIFIER12=null;
        Token COLON13=null;
        CalcParser.type_return type14 =null;


        Object VAR11_tree=null;
        Object IDENTIFIER12_tree=null;
        Object COLON13_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:73:5: ( VAR ^ IDENTIFIER COLON ! type )
            // src/vb/week3/calc/Calc.g:73:9: VAR ^ IDENTIFIER COLON ! type
            {
            root_0 = (Object)adaptor.nil();


            VAR11=(Token)match(input,VAR,FOLLOW_VAR_in_declaration915); 
            VAR11_tree = 
            (Object)adaptor.create(VAR11)
            ;
            root_0 = (Object)adaptor.becomeRoot(VAR11_tree, root_0);


            IDENTIFIER12=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_declaration918); 
            IDENTIFIER12_tree = 
            (Object)adaptor.create(IDENTIFIER12)
            ;
            adaptor.addChild(root_0, IDENTIFIER12_tree);


            COLON13=(Token)match(input,COLON,FOLLOW_COLON_in_declaration920); 

            pushFollow(FOLLOW_type_in_declaration923);
            type14=type();

            state._fsp--;

            adaptor.addChild(root_0, type14.getTree());

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "declaration"


    public static class statement_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "statement"
    // src/vb/week3/calc/Calc.g:76:1: statement : ( compound_expr | print_stat | swap_stat | dowhile_stat );
    public final CalcParser.statement_return statement() throws RecognitionException {
        CalcParser.statement_return retval = new CalcParser.statement_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        CalcParser.compound_expr_return compound_expr15 =null;

        CalcParser.print_stat_return print_stat16 =null;

        CalcParser.swap_stat_return swap_stat17 =null;

        CalcParser.dowhile_stat_return dowhile_stat18 =null;



        try {
            // src/vb/week3/calc/Calc.g:77:5: ( compound_expr | print_stat | swap_stat | dowhile_stat )
            int alt5=4;
            switch ( input.LA(1) ) {
            case IDENTIFIER:
            case IF:
            case LPAREN:
            case NUMBER:
                {
                alt5=1;
                }
                break;
            case PRINT:
                {
                alt5=2;
                }
                break;
            case SWAP:
                {
                alt5=3;
                }
                break;
            case DO:
                {
                alt5=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;

            }

            switch (alt5) {
                case 1 :
                    // src/vb/week3/calc/Calc.g:77:9: compound_expr
                    {
                    root_0 = (Object)adaptor.nil();


                    pushFollow(FOLLOW_compound_expr_in_statement946);
                    compound_expr15=compound_expr();

                    state._fsp--;

                    adaptor.addChild(root_0, compound_expr15.getTree());

                    }
                    break;
                case 2 :
                    // src/vb/week3/calc/Calc.g:78:9: print_stat
                    {
                    root_0 = (Object)adaptor.nil();


                    pushFollow(FOLLOW_print_stat_in_statement956);
                    print_stat16=print_stat();

                    state._fsp--;

                    adaptor.addChild(root_0, print_stat16.getTree());

                    }
                    break;
                case 3 :
                    // src/vb/week3/calc/Calc.g:79:9: swap_stat
                    {
                    root_0 = (Object)adaptor.nil();


                    pushFollow(FOLLOW_swap_stat_in_statement966);
                    swap_stat17=swap_stat();

                    state._fsp--;

                    adaptor.addChild(root_0, swap_stat17.getTree());

                    }
                    break;
                case 4 :
                    // src/vb/week3/calc/Calc.g:80:9: dowhile_stat
                    {
                    root_0 = (Object)adaptor.nil();


                    pushFollow(FOLLOW_dowhile_stat_in_statement976);
                    dowhile_stat18=dowhile_stat();

                    state._fsp--;

                    adaptor.addChild(root_0, dowhile_stat18.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "statement"


    public static class print_stat_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "print_stat"
    // src/vb/week3/calc/Calc.g:83:1: print_stat : PRINT ^ LPAREN ! compound_expr RPAREN !;
    public final CalcParser.print_stat_return print_stat() throws RecognitionException {
        CalcParser.print_stat_return retval = new CalcParser.print_stat_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token PRINT19=null;
        Token LPAREN20=null;
        Token RPAREN22=null;
        CalcParser.compound_expr_return compound_expr21 =null;


        Object PRINT19_tree=null;
        Object LPAREN20_tree=null;
        Object RPAREN22_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:84:5: ( PRINT ^ LPAREN ! compound_expr RPAREN !)
            // src/vb/week3/calc/Calc.g:84:9: PRINT ^ LPAREN ! compound_expr RPAREN !
            {
            root_0 = (Object)adaptor.nil();


            PRINT19=(Token)match(input,PRINT,FOLLOW_PRINT_in_print_stat999); 
            PRINT19_tree = 
            (Object)adaptor.create(PRINT19)
            ;
            root_0 = (Object)adaptor.becomeRoot(PRINT19_tree, root_0);


            LPAREN20=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_print_stat1002); 

            pushFollow(FOLLOW_compound_expr_in_print_stat1005);
            compound_expr21=compound_expr();

            state._fsp--;

            adaptor.addChild(root_0, compound_expr21.getTree());

            RPAREN22=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_print_stat1007); 

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "print_stat"


    public static class swap_stat_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "swap_stat"
    // src/vb/week3/calc/Calc.g:87:1: swap_stat : SWAP ^ LPAREN ! IDENTIFIER KOMMA ! IDENTIFIER RPAREN !;
    public final CalcParser.swap_stat_return swap_stat() throws RecognitionException {
        CalcParser.swap_stat_return retval = new CalcParser.swap_stat_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token SWAP23=null;
        Token LPAREN24=null;
        Token IDENTIFIER25=null;
        Token KOMMA26=null;
        Token IDENTIFIER27=null;
        Token RPAREN28=null;

        Object SWAP23_tree=null;
        Object LPAREN24_tree=null;
        Object IDENTIFIER25_tree=null;
        Object KOMMA26_tree=null;
        Object IDENTIFIER27_tree=null;
        Object RPAREN28_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:88:5: ( SWAP ^ LPAREN ! IDENTIFIER KOMMA ! IDENTIFIER RPAREN !)
            // src/vb/week3/calc/Calc.g:88:9: SWAP ^ LPAREN ! IDENTIFIER KOMMA ! IDENTIFIER RPAREN !
            {
            root_0 = (Object)adaptor.nil();


            SWAP23=(Token)match(input,SWAP,FOLLOW_SWAP_in_swap_stat1027); 
            SWAP23_tree = 
            (Object)adaptor.create(SWAP23)
            ;
            root_0 = (Object)adaptor.becomeRoot(SWAP23_tree, root_0);


            LPAREN24=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_swap_stat1030); 

            IDENTIFIER25=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_swap_stat1033); 
            IDENTIFIER25_tree = 
            (Object)adaptor.create(IDENTIFIER25)
            ;
            adaptor.addChild(root_0, IDENTIFIER25_tree);


            KOMMA26=(Token)match(input,KOMMA,FOLLOW_KOMMA_in_swap_stat1035); 

            IDENTIFIER27=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_swap_stat1038); 
            IDENTIFIER27_tree = 
            (Object)adaptor.create(IDENTIFIER27)
            ;
            adaptor.addChild(root_0, IDENTIFIER27_tree);


            RPAREN28=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_swap_stat1040); 

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "swap_stat"


    public static class dowhile_stat_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "dowhile_stat"
    // src/vb/week3/calc/Calc.g:91:1: dowhile_stat : DO ^ statements WHILE compound_expr ;
    public final CalcParser.dowhile_stat_return dowhile_stat() throws RecognitionException {
        CalcParser.dowhile_stat_return retval = new CalcParser.dowhile_stat_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token DO29=null;
        Token WHILE31=null;
        CalcParser.statements_return statements30 =null;

        CalcParser.compound_expr_return compound_expr32 =null;


        Object DO29_tree=null;
        Object WHILE31_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:92:5: ( DO ^ statements WHILE compound_expr )
            // src/vb/week3/calc/Calc.g:92:9: DO ^ statements WHILE compound_expr
            {
            root_0 = (Object)adaptor.nil();


            DO29=(Token)match(input,DO,FOLLOW_DO_in_dowhile_stat1060); 
            DO29_tree = 
            (Object)adaptor.create(DO29)
            ;
            root_0 = (Object)adaptor.becomeRoot(DO29_tree, root_0);


            pushFollow(FOLLOW_statements_in_dowhile_stat1063);
            statements30=statements();

            state._fsp--;

            adaptor.addChild(root_0, statements30.getTree());

            WHILE31=(Token)match(input,WHILE,FOLLOW_WHILE_in_dowhile_stat1065); 
            WHILE31_tree = 
            (Object)adaptor.create(WHILE31)
            ;
            adaptor.addChild(root_0, WHILE31_tree);


            pushFollow(FOLLOW_compound_expr_in_dowhile_stat1067);
            compound_expr32=compound_expr();

            state._fsp--;

            adaptor.addChild(root_0, compound_expr32.getTree());

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "dowhile_stat"


    public static class compound_expr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "compound_expr"
    // src/vb/week3/calc/Calc.g:95:1: compound_expr : simpel_expr ( BECOMES ^ compound_expr )? ;
    public final CalcParser.compound_expr_return compound_expr() throws RecognitionException {
        CalcParser.compound_expr_return retval = new CalcParser.compound_expr_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token BECOMES34=null;
        CalcParser.simpel_expr_return simpel_expr33 =null;

        CalcParser.compound_expr_return compound_expr35 =null;


        Object BECOMES34_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:96:3: ( simpel_expr ( BECOMES ^ compound_expr )? )
            // src/vb/week3/calc/Calc.g:96:5: simpel_expr ( BECOMES ^ compound_expr )?
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_simpel_expr_in_compound_expr1082);
            simpel_expr33=simpel_expr();

            state._fsp--;

            adaptor.addChild(root_0, simpel_expr33.getTree());

            // src/vb/week3/calc/Calc.g:96:17: ( BECOMES ^ compound_expr )?
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==BECOMES) ) {
                alt6=1;
            }
            switch (alt6) {
                case 1 :
                    // src/vb/week3/calc/Calc.g:96:18: BECOMES ^ compound_expr
                    {
                    BECOMES34=(Token)match(input,BECOMES,FOLLOW_BECOMES_in_compound_expr1085); 
                    BECOMES34_tree = 
                    (Object)adaptor.create(BECOMES34)
                    ;
                    root_0 = (Object)adaptor.becomeRoot(BECOMES34_tree, root_0);


                    pushFollow(FOLLOW_compound_expr_in_compound_expr1088);
                    compound_expr35=compound_expr();

                    state._fsp--;

                    adaptor.addChild(root_0, compound_expr35.getTree());

                    }
                    break;

            }


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "compound_expr"


    public static class simpel_expr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "simpel_expr"
    // src/vb/week3/calc/Calc.g:99:1: simpel_expr : ( expr0 | IF ^ expr0 THEN ! expr0 ELSE ! expr0 );
    public final CalcParser.simpel_expr_return simpel_expr() throws RecognitionException {
        CalcParser.simpel_expr_return retval = new CalcParser.simpel_expr_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token IF37=null;
        Token THEN39=null;
        Token ELSE41=null;
        CalcParser.expr0_return expr036 =null;

        CalcParser.expr0_return expr038 =null;

        CalcParser.expr0_return expr040 =null;

        CalcParser.expr0_return expr042 =null;


        Object IF37_tree=null;
        Object THEN39_tree=null;
        Object ELSE41_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:100:3: ( expr0 | IF ^ expr0 THEN ! expr0 ELSE ! expr0 )
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0==IDENTIFIER||LA7_0==LPAREN||LA7_0==NUMBER) ) {
                alt7=1;
            }
            else if ( (LA7_0==IF) ) {
                alt7=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 7, 0, input);

                throw nvae;

            }
            switch (alt7) {
                case 1 :
                    // src/vb/week3/calc/Calc.g:100:5: expr0
                    {
                    root_0 = (Object)adaptor.nil();


                    pushFollow(FOLLOW_expr0_in_simpel_expr1105);
                    expr036=expr0();

                    state._fsp--;

                    adaptor.addChild(root_0, expr036.getTree());

                    }
                    break;
                case 2 :
                    // src/vb/week3/calc/Calc.g:101:5: IF ^ expr0 THEN ! expr0 ELSE ! expr0
                    {
                    root_0 = (Object)adaptor.nil();


                    IF37=(Token)match(input,IF,FOLLOW_IF_in_simpel_expr1111); 
                    IF37_tree = 
                    (Object)adaptor.create(IF37)
                    ;
                    root_0 = (Object)adaptor.becomeRoot(IF37_tree, root_0);


                    pushFollow(FOLLOW_expr0_in_simpel_expr1114);
                    expr038=expr0();

                    state._fsp--;

                    adaptor.addChild(root_0, expr038.getTree());

                    THEN39=(Token)match(input,THEN,FOLLOW_THEN_in_simpel_expr1116); 

                    pushFollow(FOLLOW_expr0_in_simpel_expr1119);
                    expr040=expr0();

                    state._fsp--;

                    adaptor.addChild(root_0, expr040.getTree());

                    ELSE41=(Token)match(input,ELSE,FOLLOW_ELSE_in_simpel_expr1121); 

                    pushFollow(FOLLOW_expr0_in_simpel_expr1124);
                    expr042=expr0();

                    state._fsp--;

                    adaptor.addChild(root_0, expr042.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "simpel_expr"


    public static class expr0_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "expr0"
    // src/vb/week3/calc/Calc.g:104:1: expr0 : expr1 ( ( LESSTHAN ^| LESSEQUAL ^| GREATERTHAN ^| GREATEREQUAL ^| EQUAL ^| NOTEQUAL ^) expr1 )? ;
    public final CalcParser.expr0_return expr0() throws RecognitionException {
        CalcParser.expr0_return retval = new CalcParser.expr0_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token LESSTHAN44=null;
        Token LESSEQUAL45=null;
        Token GREATERTHAN46=null;
        Token GREATEREQUAL47=null;
        Token EQUAL48=null;
        Token NOTEQUAL49=null;
        CalcParser.expr1_return expr143 =null;

        CalcParser.expr1_return expr150 =null;


        Object LESSTHAN44_tree=null;
        Object LESSEQUAL45_tree=null;
        Object GREATERTHAN46_tree=null;
        Object GREATEREQUAL47_tree=null;
        Object EQUAL48_tree=null;
        Object NOTEQUAL49_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:105:3: ( expr1 ( ( LESSTHAN ^| LESSEQUAL ^| GREATERTHAN ^| GREATEREQUAL ^| EQUAL ^| NOTEQUAL ^) expr1 )? )
            // src/vb/week3/calc/Calc.g:105:7: expr1 ( ( LESSTHAN ^| LESSEQUAL ^| GREATERTHAN ^| GREATEREQUAL ^| EQUAL ^| NOTEQUAL ^) expr1 )?
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_expr1_in_expr01141);
            expr143=expr1();

            state._fsp--;

            adaptor.addChild(root_0, expr143.getTree());

            // src/vb/week3/calc/Calc.g:105:13: ( ( LESSTHAN ^| LESSEQUAL ^| GREATERTHAN ^| GREATEREQUAL ^| EQUAL ^| NOTEQUAL ^) expr1 )?
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( ((LA9_0 >= EQUAL && LA9_0 <= GREATERTHAN)||(LA9_0 >= LESSEQUAL && LA9_0 <= LESSTHAN)||LA9_0==NOTEQUAL) ) {
                alt9=1;
            }
            switch (alt9) {
                case 1 :
                    // src/vb/week3/calc/Calc.g:105:14: ( LESSTHAN ^| LESSEQUAL ^| GREATERTHAN ^| GREATEREQUAL ^| EQUAL ^| NOTEQUAL ^) expr1
                    {
                    // src/vb/week3/calc/Calc.g:105:14: ( LESSTHAN ^| LESSEQUAL ^| GREATERTHAN ^| GREATEREQUAL ^| EQUAL ^| NOTEQUAL ^)
                    int alt8=6;
                    switch ( input.LA(1) ) {
                    case LESSTHAN:
                        {
                        alt8=1;
                        }
                        break;
                    case LESSEQUAL:
                        {
                        alt8=2;
                        }
                        break;
                    case GREATERTHAN:
                        {
                        alt8=3;
                        }
                        break;
                    case GREATEREQUAL:
                        {
                        alt8=4;
                        }
                        break;
                    case EQUAL:
                        {
                        alt8=5;
                        }
                        break;
                    case NOTEQUAL:
                        {
                        alt8=6;
                        }
                        break;
                    default:
                        NoViableAltException nvae =
                            new NoViableAltException("", 8, 0, input);

                        throw nvae;

                    }

                    switch (alt8) {
                        case 1 :
                            // src/vb/week3/calc/Calc.g:105:15: LESSTHAN ^
                            {
                            LESSTHAN44=(Token)match(input,LESSTHAN,FOLLOW_LESSTHAN_in_expr01145); 
                            LESSTHAN44_tree = 
                            (Object)adaptor.create(LESSTHAN44)
                            ;
                            root_0 = (Object)adaptor.becomeRoot(LESSTHAN44_tree, root_0);


                            }
                            break;
                        case 2 :
                            // src/vb/week3/calc/Calc.g:105:27: LESSEQUAL ^
                            {
                            LESSEQUAL45=(Token)match(input,LESSEQUAL,FOLLOW_LESSEQUAL_in_expr01150); 
                            LESSEQUAL45_tree = 
                            (Object)adaptor.create(LESSEQUAL45)
                            ;
                            root_0 = (Object)adaptor.becomeRoot(LESSEQUAL45_tree, root_0);


                            }
                            break;
                        case 3 :
                            // src/vb/week3/calc/Calc.g:105:40: GREATERTHAN ^
                            {
                            GREATERTHAN46=(Token)match(input,GREATERTHAN,FOLLOW_GREATERTHAN_in_expr01155); 
                            GREATERTHAN46_tree = 
                            (Object)adaptor.create(GREATERTHAN46)
                            ;
                            root_0 = (Object)adaptor.becomeRoot(GREATERTHAN46_tree, root_0);


                            }
                            break;
                        case 4 :
                            // src/vb/week3/calc/Calc.g:105:55: GREATEREQUAL ^
                            {
                            GREATEREQUAL47=(Token)match(input,GREATEREQUAL,FOLLOW_GREATEREQUAL_in_expr01160); 
                            GREATEREQUAL47_tree = 
                            (Object)adaptor.create(GREATEREQUAL47)
                            ;
                            root_0 = (Object)adaptor.becomeRoot(GREATEREQUAL47_tree, root_0);


                            }
                            break;
                        case 5 :
                            // src/vb/week3/calc/Calc.g:105:71: EQUAL ^
                            {
                            EQUAL48=(Token)match(input,EQUAL,FOLLOW_EQUAL_in_expr01165); 
                            EQUAL48_tree = 
                            (Object)adaptor.create(EQUAL48)
                            ;
                            root_0 = (Object)adaptor.becomeRoot(EQUAL48_tree, root_0);


                            }
                            break;
                        case 6 :
                            // src/vb/week3/calc/Calc.g:105:80: NOTEQUAL ^
                            {
                            NOTEQUAL49=(Token)match(input,NOTEQUAL,FOLLOW_NOTEQUAL_in_expr01170); 
                            NOTEQUAL49_tree = 
                            (Object)adaptor.create(NOTEQUAL49)
                            ;
                            root_0 = (Object)adaptor.becomeRoot(NOTEQUAL49_tree, root_0);


                            }
                            break;

                    }


                    pushFollow(FOLLOW_expr1_in_expr01174);
                    expr150=expr1();

                    state._fsp--;

                    adaptor.addChild(root_0, expr150.getTree());

                    }
                    break;

            }


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "expr0"


    public static class expr1_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "expr1"
    // src/vb/week3/calc/Calc.g:108:1: expr1 : expr2 ( ( PLUS ^| MINUS ^) expr2 )* ;
    public final CalcParser.expr1_return expr1() throws RecognitionException {
        CalcParser.expr1_return retval = new CalcParser.expr1_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token PLUS52=null;
        Token MINUS53=null;
        CalcParser.expr2_return expr251 =null;

        CalcParser.expr2_return expr254 =null;


        Object PLUS52_tree=null;
        Object MINUS53_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:109:5: ( expr2 ( ( PLUS ^| MINUS ^) expr2 )* )
            // src/vb/week3/calc/Calc.g:109:9: expr2 ( ( PLUS ^| MINUS ^) expr2 )*
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_expr2_in_expr11195);
            expr251=expr2();

            state._fsp--;

            adaptor.addChild(root_0, expr251.getTree());

            // src/vb/week3/calc/Calc.g:109:15: ( ( PLUS ^| MINUS ^) expr2 )*
            loop11:
            do {
                int alt11=2;
                int LA11_0 = input.LA(1);

                if ( (LA11_0==MINUS||LA11_0==PLUS) ) {
                    alt11=1;
                }


                switch (alt11) {
            	case 1 :
            	    // src/vb/week3/calc/Calc.g:109:16: ( PLUS ^| MINUS ^) expr2
            	    {
            	    // src/vb/week3/calc/Calc.g:109:16: ( PLUS ^| MINUS ^)
            	    int alt10=2;
            	    int LA10_0 = input.LA(1);

            	    if ( (LA10_0==PLUS) ) {
            	        alt10=1;
            	    }
            	    else if ( (LA10_0==MINUS) ) {
            	        alt10=2;
            	    }
            	    else {
            	        NoViableAltException nvae =
            	            new NoViableAltException("", 10, 0, input);

            	        throw nvae;

            	    }
            	    switch (alt10) {
            	        case 1 :
            	            // src/vb/week3/calc/Calc.g:109:17: PLUS ^
            	            {
            	            PLUS52=(Token)match(input,PLUS,FOLLOW_PLUS_in_expr11199); 
            	            PLUS52_tree = 
            	            (Object)adaptor.create(PLUS52)
            	            ;
            	            root_0 = (Object)adaptor.becomeRoot(PLUS52_tree, root_0);


            	            }
            	            break;
            	        case 2 :
            	            // src/vb/week3/calc/Calc.g:109:25: MINUS ^
            	            {
            	            MINUS53=(Token)match(input,MINUS,FOLLOW_MINUS_in_expr11204); 
            	            MINUS53_tree = 
            	            (Object)adaptor.create(MINUS53)
            	            ;
            	            root_0 = (Object)adaptor.becomeRoot(MINUS53_tree, root_0);


            	            }
            	            break;

            	    }


            	    pushFollow(FOLLOW_expr2_in_expr11208);
            	    expr254=expr2();

            	    state._fsp--;

            	    adaptor.addChild(root_0, expr254.getTree());

            	    }
            	    break;

            	default :
            	    break loop11;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "expr1"


    public static class expr2_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "expr2"
    // src/vb/week3/calc/Calc.g:112:1: expr2 : operand ( ( TIMES ^| DIVIDEBY ^) operand )* ;
    public final CalcParser.expr2_return expr2() throws RecognitionException {
        CalcParser.expr2_return retval = new CalcParser.expr2_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token TIMES56=null;
        Token DIVIDEBY57=null;
        CalcParser.operand_return operand55 =null;

        CalcParser.operand_return operand58 =null;


        Object TIMES56_tree=null;
        Object DIVIDEBY57_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:113:5: ( operand ( ( TIMES ^| DIVIDEBY ^) operand )* )
            // src/vb/week3/calc/Calc.g:113:9: operand ( ( TIMES ^| DIVIDEBY ^) operand )*
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_operand_in_expr21229);
            operand55=operand();

            state._fsp--;

            adaptor.addChild(root_0, operand55.getTree());

            // src/vb/week3/calc/Calc.g:113:17: ( ( TIMES ^| DIVIDEBY ^) operand )*
            loop13:
            do {
                int alt13=2;
                int LA13_0 = input.LA(1);

                if ( (LA13_0==DIVIDEBY||LA13_0==TIMES) ) {
                    alt13=1;
                }


                switch (alt13) {
            	case 1 :
            	    // src/vb/week3/calc/Calc.g:113:18: ( TIMES ^| DIVIDEBY ^) operand
            	    {
            	    // src/vb/week3/calc/Calc.g:113:18: ( TIMES ^| DIVIDEBY ^)
            	    int alt12=2;
            	    int LA12_0 = input.LA(1);

            	    if ( (LA12_0==TIMES) ) {
            	        alt12=1;
            	    }
            	    else if ( (LA12_0==DIVIDEBY) ) {
            	        alt12=2;
            	    }
            	    else {
            	        NoViableAltException nvae =
            	            new NoViableAltException("", 12, 0, input);

            	        throw nvae;

            	    }
            	    switch (alt12) {
            	        case 1 :
            	            // src/vb/week3/calc/Calc.g:113:19: TIMES ^
            	            {
            	            TIMES56=(Token)match(input,TIMES,FOLLOW_TIMES_in_expr21233); 
            	            TIMES56_tree = 
            	            (Object)adaptor.create(TIMES56)
            	            ;
            	            root_0 = (Object)adaptor.becomeRoot(TIMES56_tree, root_0);


            	            }
            	            break;
            	        case 2 :
            	            // src/vb/week3/calc/Calc.g:113:28: DIVIDEBY ^
            	            {
            	            DIVIDEBY57=(Token)match(input,DIVIDEBY,FOLLOW_DIVIDEBY_in_expr21238); 
            	            DIVIDEBY57_tree = 
            	            (Object)adaptor.create(DIVIDEBY57)
            	            ;
            	            root_0 = (Object)adaptor.becomeRoot(DIVIDEBY57_tree, root_0);


            	            }
            	            break;

            	    }


            	    pushFollow(FOLLOW_operand_in_expr21242);
            	    operand58=operand();

            	    state._fsp--;

            	    adaptor.addChild(root_0, operand58.getTree());

            	    }
            	    break;

            	default :
            	    break loop13;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "expr2"


    public static class operand_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "operand"
    // src/vb/week3/calc/Calc.g:116:1: operand : ( IDENTIFIER | NUMBER | LPAREN ! compound_expr RPAREN !);
    public final CalcParser.operand_return operand() throws RecognitionException {
        CalcParser.operand_return retval = new CalcParser.operand_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token IDENTIFIER59=null;
        Token NUMBER60=null;
        Token LPAREN61=null;
        Token RPAREN63=null;
        CalcParser.compound_expr_return compound_expr62 =null;


        Object IDENTIFIER59_tree=null;
        Object NUMBER60_tree=null;
        Object LPAREN61_tree=null;
        Object RPAREN63_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:117:5: ( IDENTIFIER | NUMBER | LPAREN ! compound_expr RPAREN !)
            int alt14=3;
            switch ( input.LA(1) ) {
            case IDENTIFIER:
                {
                alt14=1;
                }
                break;
            case NUMBER:
                {
                alt14=2;
                }
                break;
            case LPAREN:
                {
                alt14=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 14, 0, input);

                throw nvae;

            }

            switch (alt14) {
                case 1 :
                    // src/vb/week3/calc/Calc.g:117:9: IDENTIFIER
                    {
                    root_0 = (Object)adaptor.nil();


                    IDENTIFIER59=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_operand1267); 
                    IDENTIFIER59_tree = 
                    (Object)adaptor.create(IDENTIFIER59)
                    ;
                    adaptor.addChild(root_0, IDENTIFIER59_tree);


                    }
                    break;
                case 2 :
                    // src/vb/week3/calc/Calc.g:118:9: NUMBER
                    {
                    root_0 = (Object)adaptor.nil();


                    NUMBER60=(Token)match(input,NUMBER,FOLLOW_NUMBER_in_operand1277); 
                    NUMBER60_tree = 
                    (Object)adaptor.create(NUMBER60)
                    ;
                    adaptor.addChild(root_0, NUMBER60_tree);


                    }
                    break;
                case 3 :
                    // src/vb/week3/calc/Calc.g:119:9: LPAREN ! compound_expr RPAREN !
                    {
                    root_0 = (Object)adaptor.nil();


                    LPAREN61=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_operand1287); 

                    pushFollow(FOLLOW_compound_expr_in_operand1290);
                    compound_expr62=compound_expr();

                    state._fsp--;

                    adaptor.addChild(root_0, compound_expr62.getTree());

                    RPAREN63=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_operand1292); 

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "operand"


    public static class lvalue_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "lvalue"
    // src/vb/week3/calc/Calc.g:122:1: lvalue : IDENTIFIER ;
    public final CalcParser.lvalue_return lvalue() throws RecognitionException {
        CalcParser.lvalue_return retval = new CalcParser.lvalue_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token IDENTIFIER64=null;

        Object IDENTIFIER64_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:123:5: ( IDENTIFIER )
            // src/vb/week3/calc/Calc.g:123:9: IDENTIFIER
            {
            root_0 = (Object)adaptor.nil();


            IDENTIFIER64=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_lvalue1312); 
            IDENTIFIER64_tree = 
            (Object)adaptor.create(IDENTIFIER64)
            ;
            adaptor.addChild(root_0, IDENTIFIER64_tree);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "lvalue"


    public static class type_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "type"
    // src/vb/week3/calc/Calc.g:127:1: type : INTEGER ;
    public final CalcParser.type_return type() throws RecognitionException {
        CalcParser.type_return retval = new CalcParser.type_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token INTEGER65=null;

        Object INTEGER65_tree=null;

        try {
            // src/vb/week3/calc/Calc.g:128:5: ( INTEGER )
            // src/vb/week3/calc/Calc.g:128:9: INTEGER
            {
            root_0 = (Object)adaptor.nil();


            INTEGER65=(Token)match(input,INTEGER,FOLLOW_INTEGER_in_type1336); 
            INTEGER65_tree = 
            (Object)adaptor.create(INTEGER65)
            ;
            adaptor.addChild(root_0, INTEGER65_tree);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "type"

    // Delegated rules


 

    public static final BitSet FOLLOW_statementsanddeclarations_in_program776 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_program778 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_declaration_in_statementsanddeclarations824 = new BitSet(new long[]{0x0000000040000000L});
    public static final BitSet FOLLOW_SEMICOLON_in_statementsanddeclarations826 = new BitSet(new long[]{0x000000088A40C200L});
    public static final BitSet FOLLOW_statement_in_statementsanddeclarations832 = new BitSet(new long[]{0x0000000040000000L});
    public static final BitSet FOLLOW_SEMICOLON_in_statementsanddeclarations834 = new BitSet(new long[]{0x000000088A40C202L});
    public static final BitSet FOLLOW_declaration_in_declarations862 = new BitSet(new long[]{0x0000000040000000L});
    public static final BitSet FOLLOW_SEMICOLON_in_declarations864 = new BitSet(new long[]{0x0000000800000002L});
    public static final BitSet FOLLOW_statement_in_statements891 = new BitSet(new long[]{0x0000000040000000L});
    public static final BitSet FOLLOW_SEMICOLON_in_statements893 = new BitSet(new long[]{0x000000008A40C202L});
    public static final BitSet FOLLOW_VAR_in_declaration915 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_declaration918 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_COLON_in_declaration920 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_type_in_declaration923 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_compound_expr_in_statement946 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_print_stat_in_statement956 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_swap_stat_in_statement966 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_dowhile_stat_in_statement976 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_PRINT_in_print_stat999 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_LPAREN_in_print_stat1002 = new BitSet(new long[]{0x000000000240C000L});
    public static final BitSet FOLLOW_compound_expr_in_print_stat1005 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RPAREN_in_print_stat1007 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SWAP_in_swap_stat1027 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_LPAREN_in_swap_stat1030 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_swap_stat1033 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_KOMMA_in_swap_stat1035 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_swap_stat1038 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RPAREN_in_swap_stat1040 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_DO_in_dowhile_stat1060 = new BitSet(new long[]{0x000000008A40C200L});
    public static final BitSet FOLLOW_statements_in_dowhile_stat1063 = new BitSet(new long[]{0x0000001000000000L});
    public static final BitSet FOLLOW_WHILE_in_dowhile_stat1065 = new BitSet(new long[]{0x000000000240C000L});
    public static final BitSet FOLLOW_compound_expr_in_dowhile_stat1067 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_simpel_expr_in_compound_expr1082 = new BitSet(new long[]{0x0000000000000012L});
    public static final BitSet FOLLOW_BECOMES_in_compound_expr1085 = new BitSet(new long[]{0x000000000240C000L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr1088 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr0_in_simpel_expr1105 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IF_in_simpel_expr1111 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_expr0_in_simpel_expr1114 = new BitSet(new long[]{0x0000000100000000L});
    public static final BitSet FOLLOW_THEN_in_simpel_expr1116 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_expr0_in_simpel_expr1119 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_ELSE_in_simpel_expr1121 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_expr0_in_simpel_expr1124 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr1_in_expr01141 = new BitSet(new long[]{0x00000000010C3802L});
    public static final BitSet FOLLOW_LESSTHAN_in_expr01145 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_LESSEQUAL_in_expr01150 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_GREATERTHAN_in_expr01155 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_GREATEREQUAL_in_expr01160 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_EQUAL_in_expr01165 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_NOTEQUAL_in_expr01170 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_expr1_in_expr01174 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr2_in_expr11195 = new BitSet(new long[]{0x0000000004800002L});
    public static final BitSet FOLLOW_PLUS_in_expr11199 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_MINUS_in_expr11204 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_expr2_in_expr11208 = new BitSet(new long[]{0x0000000004800002L});
    public static final BitSet FOLLOW_operand_in_expr21229 = new BitSet(new long[]{0x0000000200000102L});
    public static final BitSet FOLLOW_TIMES_in_expr21233 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_DIVIDEBY_in_expr21238 = new BitSet(new long[]{0x0000000002404000L});
    public static final BitSet FOLLOW_operand_in_expr21242 = new BitSet(new long[]{0x0000000200000102L});
    public static final BitSet FOLLOW_IDENTIFIER_in_operand1267 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NUMBER_in_operand1277 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_operand1287 = new BitSet(new long[]{0x000000000240C000L});
    public static final BitSet FOLLOW_compound_expr_in_operand1290 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RPAREN_in_operand1292 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENTIFIER_in_lvalue1312 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INTEGER_in_type1336 = new BitSet(new long[]{0x0000000000000002L});

}